import React,{Suspense} from 'react'
import {
    BrowserRouter,
    Routes,
    Route,
    Navigate
} from 'react-router-dom'
import routers from './routerConfig'
import {ROUTERTYPES} from '../types/routertypes.d'




export default function routerViets() {
    const routersDom = (router:ROUTERTYPES[])=>{
        return router.map((item,index)=>{
            return <Route key={index} path={item.path}
             element={item.to ? <Navigate to={item.to} /> : <item.component/>} >
                {
                    item.children && routersDom(item.children)
                }
            </Route>
        })
    }
  return (
    <BrowserRouter>
        <Suspense fallback={<div>路由加载中</div>}>
            <Routes>
                {
                     routersDom(routers)
                }
            </Routes>
        </Suspense>
        
        
    </BrowserRouter>
  )
}
